package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.logging.Level;
import java.util.logging.Logger;

public class COLNAME extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    String str = paramArrayOfObject[0].toString();
    int i = Integer.parseInt(paramArrayOfObject[1].toString());
    Calculator localCalculator = getCalculator();
    TableData localTableData = DataUtils.getTableData4Function(localCalculator, str);
    try
    {
      if ((localTableData == null) || (i < 1) || (i > localTableData.getColumnCount()))
        return Primitive.NULL;
      return localTableData.getColumnName(i - 1);
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    return Primitive.NULL;
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "COLNAME(tableData,colIndex)返回的是tableData中列序号colIndex的列名。\ntableData:表示TableData的名字，字符串形式。\ncolIndex:表示列序号。\n备注:\n    TableData先从私有数据源中查找，再从公有数据源中查找。\n示例:\nCOLNAME(\"Check\"，3)等于AcceName。\nCOLNAME(\"country\"，4)等于Area。";
  }

  public String getEN()
  {
    return "";
  }
}